<div class="panel panel-default panel-intro">
    <div class="panel-heading">
        {:build_heading(null, false)}
        <ul class="nav nav-tabs">
            {volist name="cates" id="vo"}
             <li {if condition="( (!empty($data)) AND ($data['cate'] eq $vo['id']) ) OR ( (!empty($cate_name)) AND  ($cate_name eq $vo['name']) ) OR ( empty($data) AND empty($cate_name) AND ($key eq 0))"} class="active" {/if}><a href="#type_{$vo.id}" data-toggle="tab">{$vo.name}</a></li>
            {/volist}
        </ul>
    </div>
    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            {volist name="cates" id="vo"}
             <div class="tab-pane fade {if condition=" ( (!empty($data)) AND ($data['cate'] eq $vo['id']) ) OR ( (!empty($cate_name)) AND  ($cate_name eq $vo['name']) ) OR ( empty($data) AND empty($cate_name) AND ($key eq 0))"} active in {/if}" id="type_{$vo.id}">
                <form id="type_{$vo.id}_form" class="form-horizontal" role="form" action=""  method="POST">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">资源类型:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="cate">
                                <option value="{$vo['id']}" selected >{$vo.name}</option>
                            </select>
                        </div>
                    </div>
                 {switch name="vo['name']" }
                   {case value="功能资源"}
                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">模块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="model" >
                                <option value="0">请选择</option>
                                {volist name="models" id="mo"}
                                <option value="{$mo['id']}" {if condition="((!empty($data)) AND $mo['id'] eq $data['model']) OR ((!empty($gongnen)) AND $mo['id'] eq $gongnen['model_id'])"}selected{/if}>{$mo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">功能:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="gongnen">
                                <option value="0">请选择</option>
                                {volist name="gongnens" id="go"}
                                <option value="{$go['id']}" {if condition="((!empty($data)) AND $go['id'] eq $data['gongnen']) OR ((!empty($gongnen)) AND $go['id'] eq $gongnen['id'])"}selected{/if}>{$go.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">功能清单:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="child_gongnen">
                                <option value="">请选择</option>
                                {volist name="child_gongens" id="ch"}
                                <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['child_gongnen']) OR ((!empty($gongnen)) AND $ch['id'] eq $gongnen['cid'])"}selected{/if}>{$ch.cname}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                   {/case}
                   {case value="模块资源"}
                       <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">模块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="model" >
                                <option value="0">请选择</option>
                                {volist name="models" id="ch"}
                                <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['model']) OR ((!empty($model)) AND $ch['id'] eq $model['id'])"}selected{/if}>{$ch.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    {/case}

                    {case value="页面资源"}

                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">板块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="plate" id="plate">
                                <option value="0">请选择</option>
                                {volist name="plates" id="ch"}
                                 <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['plate'])  OR ( (!empty($page)) AND $ch['id'] eq $page['p_id']) OR ( (!empty($plate_check)) AND $ch['id'] eq $plate_check['id'])"}selected{/if}>{$ch.name}</option>
                                  {volist name="ch['son']" id="son"}
                                    <option value="{$son.id}" {if condition="((!empty($data)) AND $son['id'] eq $data['plate']) OR ((!empty($page)) AND $son['id'] eq $page['p_id'])  OR ( (!empty($plate_check)) AND $son['id'] eq $plate_check['id'])"}selected{/if}>---{$son.name}</option>
                                  {/volist}
                                {/volist}
                            </select>
                        </div>
                    </div>

                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">页面:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="page" id="page">
                                <option value="0">请选择</option>
                                {volist name="pages" id="ch"}
                                 <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['page']) OR ((!empty($page)) AND $ch['id'] eq $page['id'])"}selected{/if}>{$ch.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    {/case}

                    {case value="板块资源"}
                      <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">板块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="plate">
                                <option value="0">请选择</option>
                                {volist name="plates" id="ch"}
                                 <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['plate'])  OR ( (!empty($plate_check)) AND $ch['id'] eq $plate_check['id'])"}selected{/if}>{$ch.name}</option>
                                {volist name="ch['son']" id="son"}
                                 <option value="{$son.id}" {if condition="((!empty($data)) AND $son['id'] eq $data['plate'])  OR ( (!empty($plate_check)) AND $son['id'] eq $plate_check['id'])"}selected{/if}>---{$son.name}</option>
                                {/volist}
                                {/volist}
                            </select>
                        </div>
                     </div>
                    {/case}
                   {case value="项目资源"}
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">项目:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="filed_id">
                                <option value="0">请选择</option>
                                {volist name="projects" id="po"}
                                 <option value="{$po['id']}" {if condition="( (!empty($data)) AND $po['id'] eq $data['filed_id'] ) OR ( (!empty($project_check)) AND $po['id'] eq $project_check['id'])"}selected{/if}>{$po.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                   {/case}
                {/switch}



                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">格式:</label>
                        <div class="col-xs-12 col-sm-8">
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><input style="position: relative;top: 2px;" type="radio" name="type" value="1" {if condition="((!empty($data)) AND $data['type'] == 1) OR (empty($data))"}checked{/if}>图片</label>
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><input style="position: relative;top: 2px;" type="radio" name="type" value="2" {if condition="(!empty($data)) AND $data['type'] == 2"}checked{/if}>代码</label>
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><input style="position: relative;top: 2px;" type="radio" name="type" value="3" {if condition="(!empty($data)) AND $data['type'] == 3"}checked{/if}>其他</label>
                        </div>
                    </div>
                    <div class="form-group ss attr attr_1">
                        <label class="control-label col-xs-12 col-sm-2">属性:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="attr['gnt']" id="ch"}
                              <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="gnt"><input style="position: relative;top: 3px;" type="radio" name="attr" {if condition="(!empty($data)) AND $data['attr'] == $ch['id']"}checked{/if}  value="{$ch.id}">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                    <div class="form-group ss attr attr_2" style="display: none;">
                        <label class="control-label col-xs-12 col-sm-2">属性:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="attr['dm']" id="ch"}
                              <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="dm"><input style="position: relative;top: 3px;" type="radio" name="attr" {if condition="((!empty($data)) AND $data['attr'] == $ch['id'])"}checked{/if} value="{$ch.id}" data-name="{$ch.name}">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                     <div class="form-group qita attr attr_3" style="display: none;">
                        <label class="control-label col-xs-12 col-sm-2">其他:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="text" name="attr" value="{$data['attr']|default=''}" class="form-control"/>
                        </div>
                    </div>


                    <div class="form-group yuyan qd" style="display: none">
                        <label class="control-label col-xs-12 col-sm-2">语言:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="language['qd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="qd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}"  {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                     <div class="form-group yuyan hd" style="display: none">
                        <label class="control-label col-xs-12 col-sm-2">语言:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="language['hd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="hd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}" {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                     <div class="form-group yuyan qz" style="display: none">
                        <label class="control-label col-xs-12 col-sm-2">语言:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="language['qd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="qd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}"  {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}
                            
                            {volist name="language['hd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="hd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}" {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}

                        </div>
                    </div>


               <div class="contianer">
                 {notempty name="data.file"}
                    {volist name="data['file']" id="file"}
                     <div class="form-group resouce">
                        <label class="control-label col-xs-12 col-sm-2">上传:</label>
                        <div class="col-xs-4 col-sm-3">
                            <input type="text" class="form-control" name="path[]" value="{$file.path}" placeholder="地址" />
                        </div>
                        <div class="col-xs-4 col-sm-3">
                            <input type="text" class="form-control" name="des[]" value="{$file.des}" placeholder="描述" />
                        </div>
                        <input type="hidden" class="form-control" name="fids[]"  value="{$file.id}"  value />
                        <div class="col-xs-4 col-sm-3" style="line-height: 27px;">
                            <span class="btn btn-xs btn-danger">删除</span>
                            <span class="btn btn-xs btn-success">查看</span>
                            <span class="btn btn-xs btn-success btn-add">添加</span>
                        </div>
                    </div>
                   {/volist}

                 {/notempty}

               </div>
                  

                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2"></label>
                        <div class="col-xs-12 col-sm-8" style="text-align: center;">
                            <input type="file" name="file" id="upload_good_img_{$vo['id']}">
                            <script type="text/javascript">
                                //上传图片\
                                var id="{$vo['id']}";
                                /* 初始化上传插件 */
                                $("#upload_good_img_"+id)
                                    .uploadify(
                                        {
                                            "height" : 30,
                                            "swf" : "__CDN__/assets/js/uploadify/uploadify.swf",
                                            "fileObjName" : "download",
                                            "buttonText" : "上传图片",
                                            "uploader" : "{:url('upload',array('session_id'=>session_id()))}",
                                            "width" : 100,
                                            'fileObjName':'file',
                                            'removeTimeout' : 1,
                                             'multi': true,
                                            "onUploadSuccess" : uploadPicture,
                                            'onFallback' : function() {
                                                alert('未检测到兼容版本的Flash.');
                                            }
                                        });
                                function uploadPicture(file, data) {
                                    var data = eval('('+data+')');
                                    var src = '';
                                    if (data.code==1) {
                                        src = data.url;

                                        /*$("input[name='path[]']").each(function(){
                                            if($(this).val()==''){
                                               $(this).val(src);
                                               return false;
                                             }
                                             
                                        })*/

                                        var str='<div class="form-group resouce">'+
                                                '<label class="control-label col-xs-12 col-sm-2"></label>'+
                                                '<div class="col-xs-4 col-sm-3">'+
                                                 '<input type="text" class="form-control" name="path[]" value="'+src+'" placeholder="地址" />'+
                                                '</div>'+
                                                '<div class="col-xs-4 col-sm-3">'+
                                                 '<input type="text" class="form-control" name="des[]" placeholder="描述" />'+
                                                '</div>'+
                                                '<input type="hidden" class="form-control" name="fids[]" value />'+
                                                '<div class="col-xs-4 col-sm-3" style="line-height: 27px;">'+
                                                '<span class="btn btn-xs btn-danger">删除</span>'+
                                                '<span class="btn btn-xs btn-success">查看</span>'+
                                                '</div>'+
                                                '</div>';
                                        $(".active .contianer").append(str);
                                 

                                    } else {
                                        alert(data.info);
                                    }
                                }
                            </script>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2"></label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="hidden" name="id" value="{$data['id']|default=''}" />
                            <button type="submit" class="btn btn-success submit">{:__('OK')}</button>
                        </div>
                    </div>
                </form>
            </div>
            {/volist}

        </div>
    </div>
</div>
<script>
    $(function() {

        $("body").on("click", ".btn-danger", function () {
            $(this).parents('.resouce').remove();
        });


        $("body").on("click", ".btn-add", function () {
            var div_clone = $(this).parents('.resouce').clone(true);
            $(this).parents('.resouce').after(div_clone);
        });

        //板块切换时
        $("body").on("click", "#plate", function () {
            var plate_id = $(this).val();
            $.ajax({
                type: 'GET',
                data: {plate_id: plate_id},
                url: "{:url('ajaxGetPage')}",
                success: function (data) {
                    $("#page").html('')
                    $("#page").append(data.msg);
                }
            });

        })

        $("input[name=type]").click(function(){
            var checked=$(this).val();

            if(checked==1){
              $(".yuyan").hide();
            }
            $(".attr").hide();
            $(".attr_"+checked).show();
            if(checked==2){
                $(".qd").show();
            }

        });

        $(".attr_2").find(":radio").click(function(){
           var name=$(this).attr('data-name');
            $(".yuyan").hide();
           switch(name){
             case "前端代码":
              $(".active .qd").show();
             break;
             case "后端代码":
              $(".active .hd").show();
             break;
             case "全栈代码":
              $(".active .qz").show();
             break;
           }
        })

        $(".submit").click(function(){   
            var data_str=$(".active form").serialize();
            var data_arr=data_str.split("&").filter(function (x) {
                return x!== "attr=";
            });

             var post_data=data_arr.join("&")   
             $.ajax({
                type:'POST',
                data:post_data,
                url:"{:url('zsave')}",
                traditional: true,
                success:function(data){
                    if(data.code==1){
                        alert(data.msg);
                        window.location.reload();
                    }else{
                        alert(data.msg);
                    }
                }
            });

            return false;  
        })

    });

</script>

